﻿@{
    ViewBag.Title = "SubProductEdit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@{
    var action = ViewData["action"].ToString();
    string Id = ViewData["Id"].ToString();
    string width = ViewData["width"].ToString();
    var companylist = ViewBag.companylist;
    var productlist = ViewBag.productlist; 
}
<style>
    .layui-form-select dl {
        max-height: 200px;
    }
</style>
<div class="mod_dialog" style="display: block; margin-top: @width; left: 0px">
    <form id="frm" class="layui-form" lay-filter="frm">
        <div class="hd">
            @{if (action == "add")
            {
                <h3>添加</h3>
            }
            else
            {<h3>修改</h3>}
            }
        </div>
        <div class="bd">
            <div class="form clearfix nouse" data-col="0">

                <ul class="form clearfix">
                    <li>
                        <label class="label">产品编号：</label>
                        <div class="inptxt" style="width:200px;">
                            <p></p>
                            <select name="PRODUCT_ID" lay-filter="PRODUCT_ID" lay-verify="required" class="layui-form-select">
                                @{
                                    <option value="">请选择</option>
                                    foreach (var product in productlist)
                                    {
                                        <option value="@product.PRODUCT_ID">@product.PRODUCT_NO-@product.COMPANY_NAME</option>
                                    }
                                }
                            </select>
                        </div>
                    </li>
                    <li>
                        <label class="label">子产品编号：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" name="SUBPRODUCT_NO" lay-filter="SUBPRODUCT_NO" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </li>
                    <li>
                        <label class="label">子产品名称：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" name="SUB_PRODUCT_NAME" lay-filter="SUB_PRODUCT_NAME" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </li>
                    <li>
                        <label class="label">子产品类型：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" name="SUB_PRODUCT_TYPE" lay-filter="SUB_PRODUCT_TYPE" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </li>
                </ul>
            </div>
        </div>
        <div class="fd">
            <div class="load_btn">
                @{if (action == "add")
                {
                    <button class="btn_green_m" id="btnAdd" lay-submit="" lay-filter="btnAdd">保存添加</button>
                    <button class="btn_gray_m" id="btnCancel">取消添加</button>
                }
                else
                {<button class="btn_green_m" id="btnEdit" lay-submit="" lay-filter="btnEdit">保存修改</button>
                    <button class="btn_gray_m" id="btnCancel" style="height:33px;width:145px">取消修改</button>
                }}
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        if ("@action" == "edit") {
            $.ajax({
                url: "/Company/GetSubProductInfoById/@Id",
                type: "post",
                dataType: "json",
                success: function (data) {
                    var form = layui.form;
                    form.val("frm", data);
                    form.render(); //刷新select选择框渲染
                }
            });
        }
        var form = layui.form;
        form.render(); //刷新select选择框渲染
        form.render('select');
        form.on('submit(btnAdd)', function (data) {
            var info = $.extend(data.field, { ID: "@Id" });
            com.ajax({
                url: "/Company/AddSubProduct", type: "post", dataType: "json", data: info, success: function (data) {
                    parent.$("#infoList").datagrid("load");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            });
            return false;
        });

        form.on('submit(btnEdit)', function (data) {
            var info = $.extend(data.field, { SUB_PRODUCT_ID: "@Id" });
            com.ajax({
                url: "/Company/EditSubProduct", type: "post", dataType: "json", data: info, success: function (data) {
                    parent.$("#infoList").datagrid("load");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            });
            return false;
        });
    });

    $("#btnCancel").click(function () {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
        return false;
    });

</script>